package com.tan.cloud_consumer.Controller;

import com.api.cloud_api.Entity.CommonResult;
import com.api.cloud_api.Entity.Pay;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
public class PayController {
    public static final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVICE";

    @Resource
    private RestTemplate restTemplate;

    @GetMapping("/create")
    public CommonResult<Pay> create(Pay payment){

        return restTemplate.postForObject(PAYMENT_URL+"/Pay/create", payment, CommonResult.class);

    }

    @GetMapping("/get/{id}")
    public CommonResult<Pay> getPayment(@PathVariable("id") Long id) {
        return restTemplate.getForObject(PAYMENT_URL + "/Pay/get/" + id, CommonResult.class);

//        return new CommonResult(200,"成功",r);
    }

}
